<template>
  <div>
    <el-card class="box-card">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="角色名称" width="180">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="角色权限">
          <template #default="scope">
            <el-tag :key="index" v-for="(item, index) in scope.row.permission">{{
              permisDatas[item]
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
// import { Timer } from '@element-plus/icons-vue'
import { getRoleList } from '@/api/role'
import { ref } from 'vue'
import { MainRoutes } from '@/router'
interface User {
  date: string
  name: string
  address: string
}

const getPerData = () => {
  let obj = {}
  const loop = (arr) => {
    arr.forEach((e) => {
      obj[e.path] = e.meta.title
      if (e.children) {
        loop(e.children)
      }
    })
  }
  loop(MainRoutes)
  return obj
}
let permisDatas = getPerData()
console.log('路由列表', getPerData())
let tableData = ref([])
const getRoleLists = async () => {
  let res = await getRoleList()
  tableData.value = res.data.results
  // console.log("角色列表", tableData.value)
  // console.log("路由", MainRoutes)
}

getRoleLists()

const handleEdit = (index: number, row: User) => {
  console.log(index, row)
}
const handleDelete = (index: number, row: User) => {
  console.log(index, row)
}
</script>

<style scoped></style>
